//
//  TestDetailThirdViewController.m
//  Koizora
//
//  Created by dlios on 15-6-11.
//  Copyright (c) 2015年 CupCat. All rights reserved.
//

#import "TestDetailThirdViewController.h"
#import "NetworkHandle.h"
#import "TestDetailSecondViewController.h"
#import "TestDetailSecondModel.h"
//#import "TestDetailModel.h"
#import <UIImageView+WebCache.h>

@interface TestDetailThirdViewController ()
@property (nonatomic, strong) NSMutableArray *thirdArr;

@end

@implementation TestDetailThirdViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self getData];
    
}

- (void)createDetailThreeView
{
    self.coverImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height / 4)];
    [_coverImgView sd_setImageWithURL:[NSURL URLWithString:[[_thirdArr firstObject] coverImg]]placeholderImage:nil];
//    _coverImgView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:_coverImgView];
    
    self.option = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"00"]];
    _option.frame = CGRectMake(20, _coverImgView.frame.size.height + _coverImgView.frame.origin.y + 10, self.view.bounds.size.width / 4, self.view.bounds.size.width / 4);
    [self.view addSubview:_option];
    self.optionNumView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width / 4, self.view.bounds.size.width / 4)];
    _optionNumView.font = [UIFont systemFontOfSize:60];
    _optionNumView.textAlignment = 1;
    _optionNumView.text = [_thirdDic objectForKey:@"answerNum"];
    [_option addSubview:_optionNumView];
    
    self.answer = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width / 3, _option.frame.size.height + _option.frame.origin.y - 30, self.view.bounds.size.width / 3, 30)];
//    _answer.backgroundColor = [UIColor yellowColor];
    _answer.text = @"测试结果";
    _answer.textAlignment = 1;
    [self.view addSubview:_answer];
    
       NSLog(@"%@", _thirdDic);
   
    
    self.Content = [[UIScrollView alloc] initWithFrame:CGRectMake(10,_option.frame.size.height + _option.frame.origin.y + 20, self.view.bounds.size.width - 20, 500)];
    _Content.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width - 40, 600);
//    _Content.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:_Content];
    
    CGFloat f = [[self class] heightWithText:[_thirdDic objectForKey:@"anwserContent"]];
    self.answerContent = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _Content.frame.size.width, f)];
    _answerContent.text = [_thirdDic objectForKey:@"anwserContent"];
    _answerContent.numberOfLines = 0;
//    _answerContent.backgroundColor = [UIColor greenColor];
    [_Content addSubview:_answerContent];
    
    
    
    
    
    
}

-(void)getData
{
    NSString *qq = [NSString stringWithFormat:@"http://star.zhuoyouapp.com/v1/questionnaireServer/getTestById.action?testId=%@", _testID];
    [NetworkHandle getDataWithURL:qq completion:^(id result) {
        self.thirdArr = [NSMutableArray array];
        TestDetailSecondModel *secondModel = [[TestDetailSecondModel alloc] initWithDic:[result objectForKey:@"testEntity"]];
        [self.thirdArr addObject:secondModel];
        NSLog(@"%@",secondModel);
        
        [self createDetailThreeView];
        
        

    }];
}

+(CGFloat)heightWithText:(NSString *)text
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake([UIScreen mainScreen].bounds.size.width - 40, 1000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
